#方法一
import os

# dir_path = r'E:\pycharm_out\yufa\git_test'
# list_file = os.listdir(dir_path)
#
# txt_path = os.path.join(dir_path,'文件夹信息.txt')
#
# with open(txt_path, 'w', encoding='utf8') as w:
#     w.write(str(list_file))

#方法二
def write_list(path,text_name):
    dir_path1 = path
    list_file1 = os.listdir(dir_path1)
    txt_path1 = os.path.join(dir_path1,text_name)
    txt_path2,txt_path3 = os.path.splitext(text_name)
    txt_path4 = os.path.join(dir_path1,txt_path2+"1"+txt_path3)


    if not os.path.exists(txt_path1):
        with open(txt_path1, 'w', encoding='utf8') as w:
            w.write(str(list_file1))
    else:
        with open(txt_path4, 'w', encoding='utf8') as w:
            w.write(str(list_file1))

        open_text = os.startfile(txt_path1)

path = str(input('请输入一个路径:'))
text_name = str(input('请输入一个文本名称(记得加文本尾缀):'))
write_list(path,text_name)